import { getRequest } from '@/api/interceptor'
import { translatePlaylist, transPlaylistDetail, transSongDetailList } from '@/api/playLists/translate'
import { translateComment, translateLastComment } from '@/api/video/translate'

const REQUEST_URL = {
  detail: '/playlist/detail',
  comment: '/comment/playlist',
  allCatlist: '/playlist/catlist',
  hotCatlist: '/playlist/hot',
  qualityCatlist: '/playlist/highquality/tags',
  topPlaylist: '/top/playlist',
  highquality: '/top/playlist/highquality',
  songDetailList: '/song/detail'
}

export const getAllCatlist = () => {
  return getRequest(REQUEST_URL.allCatlist)
}

export const getHotCatlist = () => {
  return getRequest(REQUEST_URL.hotCatlist)
}

export const getPlaylist = (obj: { cat: string; offset?: number; limit?: number }) => {
  return getRequest(REQUEST_URL.topPlaylist, obj).then(translatePlaylist)
}

export const getHighquality = (obj: { cat: string; limit?: number; before?: number }) => {
  return getRequest(REQUEST_URL.highquality, obj).then(translatePlaylist)
}

export const getHighqualityCatlist = () => {
  return getRequest(REQUEST_URL.qualityCatlist)
}

export const getPlaylistDetail = (id) => {
  return getRequest(REQUEST_URL.detail, { id }).then(transPlaylistDetail)
}

export const getPlaylistComment = ({ id, limit = 20, offset }) => {
  return getRequest(REQUEST_URL.comment, { id, limit, offset: offset * limit }).then(translateComment)
}

export const getPlaylistLastestComment = ({ id, limit = 20, offset }) => {
  return getRequest(REQUEST_URL.comment, { id, limit, offset: offset * limit }).then(translateLastComment)
}

export const getSongDetailList = (ids) => {
  return getRequest(REQUEST_URL.songDetailList, { ids }).then(transSongDetailList)
}
